import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_app_open_camera/base/toolbar_view.dart';
import 'package:flutter_app_open_camera/utils/ex.dart';

import 'loading_view.dart';

class BaseContainer extends StatefulWidget {
  final Widget child;
  final Widget floatingActionButton;
  final Widget icon; //左侧按钮
  final Widget rightIcon; //右侧按钮
  final String title; //标题
  final BoxDecoration bgBoxDecoration; //背景样式
  final Color toolbarBgColor; //toolbar背景色
  final Color statusBgColor; //statusBar背景色
  final Function backIconPress; //toolbar 左边点击事件
  final Function rightIconPress; //toolbar 右边点击事件
  final bool showToolBar; //是否显示toolbar
  final bool statusDarkColor; //statusBar字体颜色 true 黑色 false 白色
  final double titleSize; //标题字体大小
  final double toolbarHeight; //toolbar高度
  final bool rightIconShow; //右侧按钮是否显示
  final bool loadingShow; //是否显示loading页面
  final Color titleColor; //标题字体颜色

  BaseContainer({
    Key key,
    this.child,
    this.floatingActionButton,
    this.backIconPress,
    this.rightIconPress,
    this.bgBoxDecoration,
    this.statusDarkColor = true,
    this.showToolBar = false,
    this.rightIconShow = false,
    this.title = "",
    this.titleSize,
    this.toolbarHeight,
    this.toolbarBgColor = Colors.white,
    this.statusBgColor = Colors.white,
    this.titleColor = Colors.black,
    this.icon = const Icon(Icons.arrow_back_rounded),
    this.rightIcon,
    this.loadingShow = false,
  }) : super(key: key);

  @override
  _BaseContainerState createState() => _BaseContainerState();
}

class _BaseContainerState extends State<BaseContainer> {
  @override
  Widget build(BuildContext context) {
    return AnnotatedRegion(
      value: widget.statusDarkColor
          ? SystemUiOverlayStyle.dark
          : SystemUiOverlayStyle.light,
      child: Scaffold( backgroundColor: Colors.transparent,
        body: Stack(
          children: [
            Padding(
              padding: EdgeInsets.only(
                top: widget.showToolBar
                    ? getStatusBarHeight() + widget.toolbarHeight
                    : 0.0,
              ),
              child: widget.loadingShow
                  ? LoadingView()
                  : Container(
                      height: double.infinity,
                      decoration: widget.bgBoxDecoration,
                      width: double.infinity,
                      child: widget.child),
            ),
            widget.showToolBar
                ? Toolbar(
                    rightIconShow: widget.rightIconShow,
                    toolbarBgColor: widget.toolbarBgColor,
                    toolbarHeight: widget.toolbarHeight,
                    backIconPress: widget.backIconPress,
                    rightIconPress: widget.rightIconPress,
                    icon: widget.icon,
                    rightIcon: widget.rightIcon,
                    title: widget.title,
                    titleColor: widget.titleColor,
                    titleSize: widget.titleSize,
                    statusBgColor: widget.statusBgColor,
                  )
                : SizedBox(),
          ],
        ),
        floatingActionButton: widget.floatingActionButton,
      ),
    );
  }
}
